import {createApp} from 'vue'
import AppLoading from "./components/common/app-loading.vue";
import {setupAssets} from "./plugins";
import App from "./App.vue";
import {setupStore} from "./store";
import {setupRouter} from "./router";

async function setupApp() {
    // import assets: js、css
    setupAssets();

    // app loading
    const appLoading = createApp(AppLoading);
    appLoading.mount('#appLoading');

    const app = createApp(App);
    setupStore(app);

    await setupRouter(app);

    appLoading.unmount();
    // mount app
    app.mount('#app');

    // // 全局禁用右键菜单
    // app.config.globalProperties.$onContextmenu = (event: Event) => {
    //     event.preventDefault();
    // };
    //
    // // 在应用挂载后绑定全局事件监听器
    // document.addEventListener('contextmenu', app.config.globalProperties.$onContextmenu);

    // 全局禁用浏览器前进后退
    window.addEventListener('popstate', () => {
        window.history.pushState(null, '', window.location.href)
    })
}

setupApp();
